package cn.darkhorse.core.param;


import cn.darkhorse.core.consts.WorkflowParamConsts;
import cn.darkhorse.core.param.IParamParserStrategy;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 获取解析策略的简单工厂
 * @author yuanjun
 * @since 2020/6/3 15:50
 */
@Component
public class ParamParserStrategyFactory {
    private Map<String, IParamParserStrategy> cacheStrategy = new ConcurrentHashMap<>(16);

    public IParamParserStrategy getParamParserStrategy(String workflowParamClass) {
        return cacheStrategy.get(workflowParamClass);
    }

    public ParamParserStrategyFactory() {
        this.cacheStrategy.put(WorkflowParamConsts.CLASS_TASK_USER,new ParserStrategy4TaskUser());
        this.cacheStrategy.put(WorkflowParamConsts.CLASS_FLOW,new ParserStrategy4Flow());
    }

    public void addParamParserStrategy(String workflowParamClass, IParamParserStrategy strategy) {
        this.cacheStrategy.put(workflowParamClass,strategy);
    }
}
